<admintpl file="header" />
</head>
<body class="J_scroll_fixed">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a href="{:U('Tui/Agent/setGameAllAgentRate')}" target="_self">统一设置游戏折扣和返点</a></li>
        </ul>
        <form class="well form-search" method="get" action="{:U('Tui/Agent/setGameAllAgentRate')}">
            <div class="search_type cc mb10">
                <div class="mb10">
                    <span class="mr20">
                        游戏名：
                        <input type="text" name="gamename" />
                        &nbsp;&nbsp; 
                        <input type="submit" class="btn btn-primary" value="搜索" />
                    </span>
                </div>
            </div>
        </form>

        <form class="js-ajax-form" action="" method="post">
            <table class="table table-hover table-bordered table-list">
                <thead>
                    <tr>
                        <th width="20">游戏ID</th>
                        <th width="50">游戏名称</th> 
                        <th width="100">当前折扣<span style="font-size:12px;font-weight: normal;color:grey;">（只影响后续申请，供参考）</span></th> 
                        
                        
                        <th width="50">操作</th>
                    </tr>
                </thead>

                <foreach name="items" item="vo">
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.agent_rate}</td>
                        
                        <td>
                            <a href="#" class="edit_rate_btn" data-name="{$vo.name}" 
                               data-dar="{$vo.agent_rate}" data-dr="{$vo.rebate}"
                               data-id="{$vo.id}">统一设置折扣</a> 
                            
                        </td>                          
                    </tr>
                </foreach>				
            </table>
            <div class="pagination">{$Page}</div>
        </form>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <script>

        $(".edit_rate_btn").click(function(){
            var id=$(this).attr("data-id");
            var name=$(this).attr("data-name");
            
            var con=confirm("您真的要统一设置此游戏【"+name+"】的折扣吗？\r\n这将把所有此游戏相关的渠道申请的折扣修改成您设置的数值，请谨慎操作");
            if(!con){
                return;
            }
            
            var dar=$(this).attr("data-dar");
            var new_rate=prompt("请输入新的折扣",dar);
            if (new_rate!==null && new_rate!=="" && !isNaN(new_rate)){
                $.post("{:U('tui/agent/setGameAllAgentRate_post')}",{"id":id,"new_rate":new_rate},function(data){
                    if(data.error==='0'){
                        alert(data.msg);
                        location.reload();
                    }else{
                        alert(data.msg);
                    }
                });
            }
        });
        
        $(".edit_rebate_btn").click(function(){
            var id=$(this).attr("data-id");
            var name=$(this).attr("data-name");
            var con=confirm("您真的要统一设置此游戏【"+name+"】的返点吗？\r\n这将把所有此游戏相关的渠道申请的返点修改成您设置的数值，请谨慎操作");
            if(!con){
                return;
            }
            
            var drr=$(this).attr("data-dr");
            var new_rate=prompt("请输入新的返点",drr);
            if (new_rate!==null && new_rate!=="" && !isNaN(new_rate)){
                $.post("{:U('tui/agent/setGameAllAgentRebate_post')}",{"id":id,"value":new_rate},function(data){
                    if(data.error==='0'){
                        alert(data.msg);
                        location.reload();
                    }else{
                        alert(data.msg);
                    }
                });
            }
        });
    </script>
</body>
</html>